// pages/my/my.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    index: 0, //tab栏
  },
  btn_login() {
    wx.getUserProfile({
      desc: '用于完善用户信息',
      success: (res) => {
        console.log(res);
        wx.setStorageSync('users', res.userInfo)
        wx.showToast({
          title: '登录成功',
        })
        this.setData({
          users: wx.getStorageSync('users').userInfo
        })
      }
    })
    setTimeout(() => {
      wx.switchTab({
        url: '../my/my',
      })
    }, 2000);
  },
  myData(e) {
    console.log(e);
    wx.navigateTo({
      url: `../../detaiPage/detaiPage/detaiPage?index_id=${e.currentTarget.dataset.index}`,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  netlogin_user() {
    wx.navigateTo({
      url: '../foodRelease/foodRelease',
    })
  },
  onLoad: function () {
    console.log(2);
  },
  btn(e) {
    let index = e.currentTarget.dataset.index
    // console.log(index);
    this.setData({
      index
    })
    if (this.data.index == 2) {
      wx.cloud.callFunction({
        name: 'my',
        data: {
          code: 5
        },
        success: res => {
          console.log(res);
          this.setData({
            list1: res.result
          })
        },
        fail(err) {
          console.log(err);
        }
      })
    }
  },
  focusOn(e) {
    console.log(e);
    wx.navigateTo({
      url: `../../detaiPage/detaiPage/detaiPage?index_id=${e.currentTarget.dataset.type}`,
    })
  },
  ification(e) {
    console.log(e.currentTarget.dataset.index_id);
    wx.navigateTo({
      url: `../../list/list/list?typeId=${e.currentTarget.dataset.index_id}&code=5`,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // console.log(1);
    if (wx.getStorageSync('users')) {
      console.log(1);
      let res = wx.getStorageSync('users');
      this.setData({
        users: res
      })
      wx.cloud.callFunction({
        name: 'my',
        data: {
          code: 2
        },
        success: res => {
          console.log(res);
          this.setData({
            list: res.result.data
          })
        },
        fail: err => {
          console.log(err);
        }
      })
    } else {
      console.log(2);
      wx.showToast({
        title: '请先登录!',
      })
    }

  },
  onLoad: function () {
    wx.cloud.callFunction({
      name: 'my',
      data: {
        code: 5
      },
      success: res => {
        console.log(res);
        this.setData({
          list1: res.result.list
        })
      },
      fail(err) {
        console.log(err);
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})